#pragma once

class ICfTask;

class CCloudManager
{
public:
	CCloudManager();
	~CCloudManager();

	bool Init();
	void Exit();
	void AddTask(const std::shared_ptr<ICfTask>& pTask);
	void RemoveTask(INT64 nTaskKey, bool bCancel = false);
	void CancelTasks();

private:
	void InitDeviceMapping();
	void LogCallbackInfo(LPCWSTR lpType, const CF_CALLBACK_INFO *pCallbackInfo);
	static void InitPlaceholders();
	static void CreatePlaceholders(const std::wstring& strPathName, const std::vector<std::wstring>& vecFileNames);
	static LPCWSTR GetSubPathOnRoot(LPCWSTR lpSubPath);
	static void CALLBACK OnFetchData(const CF_CALLBACK_INFO *pCallbackInfo, const CF_CALLBACK_PARAMETERS *pCallbackParameters);
	static void CALLBACK OnCancelFetchData(const CF_CALLBACK_INFO *pCallbackInfo, const CF_CALLBACK_PARAMETERS *pCallbackParameters);
	static void CALLBACK OnFetchPlaceholders(const CF_CALLBACK_INFO *pCallbackInfo, const CF_CALLBACK_PARAMETERS *pCallbackParameters);
	static void CALLBACK OnCancelFetchPlaceholders(const CF_CALLBACK_INFO *pCallbackInfo, const CF_CALLBACK_PARAMETERS *pCallbackParameters);

	static LockExit   m_lockExit;	// Prevent CloudManager from exiting

	CF_CONNECTION_KEY m_connectionKey;
	HANDLE            m_hExitEvent;
	SRWLOCK           m_SRWLock = SRWLOCK_INIT;
	std::unordered_map<INT64, std::weak_ptr<ICfTask>> m_mapTasks;
	std::vector<std::pair<wchar_t, std::wstring>> m_vecDosDevices;	// For log only
};
